package com.baichang.taoshunda.dao.impl;

import com.baichang.framework.dao.impl.BaseDaoImpl;
import com.baichang.framework.model.Page;
import com.baichang.taoshunda.dao.RebateDao;
import com.baichang.taoshunda.entity.Rebate;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author Dylan
 * @date 2018/12/14 0014 16:38
 * @company Dylan
 * @description
 */
@Repository
public class RebateDaoImpl extends BaseDaoImpl<Rebate> implements RebateDao {
    @Override
    public Integer getRebateCount(Integer userId) {
        String sql = "SELECT COUNT(0) FROM t_rebate_amount WHERE user_id=?";
        return queryForInt(sql, userId);
    }

    @Override
    public List<Map<String, Object>> findRebateList(Integer userId, Integer nowPage, Integer pageSize) {
        String sql = "SELECT * FROM t_rebate_amount WHERE user_id =? AND `status`=1";
        return listForMapList(sql, nowPage, pageSize, userId);
    }

    @Override
    public int findRebateListCount(Integer userId) {
        String sql = "SELECT count(0) FROM t_rebate_amount WHERE user_id =? AND `status`=1";
        return queryForInt(sql, userId);
    }

    @Override
    public boolean cancelRebate(Integer rebateId) {

        return update("UPDATE `t_rebate_amount` SET `status`='0' WHERE (`id`= ? )", rebateId) > 0;
    }

    @Override
    public Page queryCompanyOrderList(Integer id, int nowPage, int pageSize) {
        String sql = "SELECT ra.*,o.goods_all_money goodsAllMoney FROM t_rebate_amount ra\n" +
                "INNER JOIN t_order o ON o.order_number =ra.order_number\n" +
                "WHERE ra.company_id=?  ORDER BY ra.id DESC";
        return pageForMapList(sql, nowPage, pageSize, id);
    }
}
